package com.hengyue.system.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hengyue.common.annotation.Excel;
import com.hengyue.common.core.entity.CoreBaseDataEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
@Entity
public class SysRole extends CoreBaseDataEntity {

    /**
     * 显示顺序
     */
    private Integer roleSort;

    @ManyToMany(mappedBy = "sysRoles",fetch = FetchType.LAZY)
    @JsonIgnore
    private Set<SysUser> users = new HashSet<>();

    private String roleKey;

    /** 菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示） */
    private boolean menuCheckStrictly;

    /** 部门树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ） */
    private boolean deptCheckStrictly;

    /** 用户是否存在此角色标识 默认不存在 */
    private boolean flag = false;

    /** 删除标志（0 代表存在 2 代表删除） */
    private String delFlag = "0";

    @Excel(name = "角色状态", readConverterExp = "0=正常,1=停用")
    private String status;


    /** 角色菜单权限 */
    /** 角色菜单权限 */
   /* @ElementCollection
    @CollectionTable(name = "role_permissions", joinColumns = @JoinColumn(name = "role_id"))
    @Column(name = "permission")
    private Set<String> permissions;*/

    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY,cascade = CascadeType.REMOVE)
    @JoinTable(name = "role_menu",
            joinColumns = @JoinColumn(name="role_id"),
            inverseJoinColumns = @JoinColumn(name = "menu_id"))
    private Set<SysMenu> menus;

}